import http from '@/utils/service';

const API = {
  saveOrUpdateDish: '/dish/saveOrUpdateDish',
  upload: '/ftp/upload',
  getDish: '/dish/getDish',
  getDishById: '/dish/getDishByIds',
  delDishById: '/dish/delete?id=',
  getDishPhoto: '/dish/getDishPhoto',
};

export interface DataType {
  id: number;
  image: string;
  name: string;
  classify: number;
  number: number;
  score: number;
  sales: number;
  price: number;
}

export interface saveOrUpdateDish {
  restaurantId: number;
  id?: number;
  image: string;
  name: string;
  price: number;
  classify: number;
  number: number;
}

export interface getDishPage {
  name: string;
  classify: number;
  current: number;
  restaurantId: number;
  size: number;
  sortField: string;
  sortOrder: string;
}

export const saveOrUpdateDishApi = (data: saveOrUpdateDish) =>
  http.post(API.saveOrUpdateDish, { data });

export const getDishAPI = (data: getDishPage) =>
  http.post(API.getDish, { data });

export const getDishByIdAPI = (data: number[]) =>
  http.post(API.getDishById, { data });

export const delDishByIdAPI = (id: string) => http.delete(API.delDishById + id);
export const getDishPhotoAPI = (id: number) =>
  http.get(API.getDishPhoto, { params: { id } });
